package com.ssplayer.adapter;

import java.util.List;

import android.annotation.SuppressLint;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.ssplayer.activity.R;
import com.ssplayer.bean.Music;
import com.ssplayer.bean.MusicList;
import com.ssplayer.utils.MediaUtils;

public class MusicListAdapter extends BaseAdapter {

	private Context context;
	private List<MusicList> lists;
	private MusicList musicList;
	private int item_layout;

	public MusicListAdapter() {
	}

	/**
	 * 不同的地方显示布局不同，需传入一个布局ID
	 * 
	 * @param context
	 * @param lists
	 * @param item_layout
	 */
	public MusicListAdapter(Context context, List<MusicList> lists,
			int item_layout) {
		this.lists = lists;
		this.context = context;
		this.item_layout = item_layout;
	}

	@Override
	public int getCount() {
		return lists.size();
	}

	@Override
	public Object getItem(int position) {
		return lists.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@SuppressLint({ "NewApi", "InflateParams" })
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		MusicHolder musicHolder = null;
		if (convertView == null) {
			musicHolder = new MusicHolder();
			convertView = LayoutInflater.from(context).inflate(item_layout,
					null);
			musicHolder.musiclist_id = (TextView) convertView
					.findViewById(R.id.musiclist_id);
			musicHolder.musiclist_title = (TextView) convertView
					.findViewById(R.id.musiclist_title);
			convertView.setTag(musicHolder);
		} else {
			musicHolder = (MusicHolder) convertView.getTag();
		}
		musicList = lists.get(position);
		musicHolder.musiclist_id.setText(String.valueOf(musicList.getId()));
		musicHolder.musiclist_title.setText(musicList.getTitle());
		return convertView;
	}

	private class MusicHolder {
		TextView musiclist_id;
		TextView musiclist_title;
	}

}
